package com.bootcamp.javase.polymorph;

/**
 * @program: PolyMorphCode
 * @description:
 * @author: Keyu Li
 * @create: 2021-09-02 21:18
 **/

public class TestPerson {
    public static void main(String[] args) {
        NorthPerson np = new NorthPerson("li ming", 18, 1.99);
        SouthPerson sp = new SouthPerson("wang ning", 22,33000.9);
        np.eat();
        sp.eat();

        Person pn = new NorthPerson("dong dong", 12, 1.59);
        Person ps = new SouthPerson("hua hua", 39, 9000.1);
        System.out.println(((SouthPerson) ps).salary);
        ((SouthPerson) ps).swim();
        System.out.println( ((SouthPerson) pn).salary);
        ((SouthPerson) pn).swim();
    }
}

class Person{
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    void  eat(){
        System.out.println("eat food!");
    }

    Person(){}
}

class  SouthPerson extends Person {
    double salary;

    public SouthPerson(String name, int age, double salary) {
        super(name, age);
        this.salary = salary;
    }

    public SouthPerson(double salary) {
        this.salary = salary;
    }

    void eat(){
        System.out.println("eat rice!");
    }
    void swim(){
        System.out.println("swim!");
    }
}

class NorthPerson extends Person {
    double height;

    public NorthPerson(String name, int age, double height) {
        super(name, age);
        this.height = height;
    }

    public NorthPerson() {
    }

    void eat(){
        System.out.println("eat noodles!");
    }
    void drink(){
        System.out.println("drink water!");
    }
}
